package tech.aistar.day01.HomeWork;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Employee {
    //id
    private int id;
    //name
    private String name;
    //salary
    private double salary;
    //上司
    private Employee[] employees;

    public Employee(int id, String name, double salary) {
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public Employee[] getEmployees() {
        return employees;
    }

    public void setEmployees(Employee[] employees) {
        this.employees = employees;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Employee{");
        sb.append("id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", salary=").append(salary);
        sb.append(", employees=").append(employees == null ? "null" : Arrays.asList(employees).toString());
        sb.append('}');
        return sb.toString();
    }

    //添加
    public void addEmp(Employee employee){
        if(employees==null){
            System.out.println("sorry,没有权限");
        }
        employees= Arrays.copyOf(employees,employees.length+1);
        employees[employees.length-1]=employee;
    }
    //输出所有下属
    public void findAll(){
        if(null!=employees&&employees.length>0){
            for(Employee employee:employees){
                System.out.println(employee);
            }
        }else{
            System.out.println("sorry,先添加");
        }

    }
    //输出下属人数
    public void countOfEmployees(){
        System.out.println(employees.length);
    }
    //根据id删除下属
    public void delById(int id){
        Employee[] newempl=new Employee[employees.length-1];
        for (int i = 0; i < newempl.length; i++) {
            if(i<id-1){
                newempl[i]=employees[i];
            }else {
                newempl[i]=employees[i+1];
            }
        }
        System.out.println(Arrays.toString(newempl));
    }
    //开除薪资大于1500的下属
    public void delByPrice(double price){
        Employee[] newempl=new Employee[employees.length];
        for (int i = 0,k=0; i < employees.length; i++) {
            if(employees[i].getSalary()>1500.0d){
                newempl[k]=employees[k];
                k++;
            }
        }
        System.out.println(Arrays.toString(newempl));
    }
}